/*
============================================================================
 Name        : sd_platform.cpp
 Author      : Jian
 Version     :
 Copyright   : GPL
 Description : sd_platform.cpp - source file
============================================================================
*/

/* INCLUDE FILES */
#include "sd_platform.h"
#include "dd_log.h"
#include <f32file.h>
#include <bautils.h>
#include <stringloader.h>
#include <sys\types.h>
#include <sys\time.h>
#include <netinet\in.h>
#include <aknutils.h>
#include <e32math.h>
#include <UTF.H>


RFs* fileFs = NULL ;

extern void sym_network_init() ;

void sd_env_init() 
{
    TRAPD(
        err,
        fileFs = new(ELeave) RFs ;
        User::LeaveIfError(fileFs->Connect());
        User::LeaveIfError(fileFs->ShareAuto()); 
        __DD_ASSERT(err == KErrNone) ;
        ) ;
    
    sym_network_init() ;
}

void sd_send_msg_to_ui(int msgId, void* msgPtr, int msgLen) 
{
    
}

/* must return with the last directory slash like / or \ */
void sd_get_log_path(char path[DD_MAX_FILE_NAME_LEN + 1]) 
{
    __DD_ASSERT_DEFENSE(path, return) ;

    strcpy(path, "c:\\data\\player\\debug\\") ;
}

void sd_get_time_string(char str[DD_MAX_TIME_STR_LEN + 1]) 
{
    __DD_ASSERT_DEFENSE(str, return) ;

    struct tm *ptm;
    struct timeval timeSecs;
    gettimeofday(&timeSecs, 0);
    ptm = localtime((int*)(&timeSecs.tv_sec));
    timeSecs.tv_usec = timeSecs.tv_usec / 1000;
    sprintf(str, "%04d-%02d-%02d %02d:%02d:%02d:%03d ", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)timeSecs.tv_usec);
}

void sd_get_thread_info(char threadInfo[DD_MAX_THREAD_INFO_LEN + 1]) 
{
    __DD_ASSERT_DEFENSE(threadInfo, return) ;

    sprintf(threadInfo, "%d", TUint(RThread().Id())) ;
}

void sd_sys_log(DD_UINT priority, const char* logStr, ...) 
{
    
}

void sd_get_ini_file(char* fileName) 
{
    __DD_ASSERT_DEFENSE(fileName, return) ;

    strcpy(fileName, "c:\\data\\player\\config.ini") ;
}

int  sd_get_local_file_name(int id, char fileName[DD_MAX_TIME_STR_LEN + 1]) 
{
    __DD_ASSERT_DEFENSE(fileName, return -1) ;

    strcpy(fileName, "c:\\data\\player\\test.mp3") ;

    return 0 ;
}

int  sd_get_cur_time(sd_time* time) 
{
    __DD_ASSERT_DEFENSE(time, return -1) ;

    struct timeval systemTime;
    gettimeofday(&systemTime, 0);
    time->second = systemTime.tv_sec ;
    time->usecond = systemTime.tv_usec ;
    return 0 ;
}

int  sd_sleep(int second) 
{
    User::After(second * 1000000) ;
}

int  sd_get_cpu_count() 
{
    return 1 ;
}


/* End of File */
